package com.antis.olsl.data.order;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.antis.olsl.base.BaseActivity;
import com.antis.olsl.data.adapter.DistributionInfoFiledListAdapter;
import com.antis.olsl.data.databinding.ActivityOrderGoodsDetailsBinding;
import com.antis.olsl.data.response.GetOrderGoodsDetailsData;
import com.antis.olsl.library.bean.GoodsFiledInfo;
import com.antis.olsl.library.response.OrderInfo;
import com.antis.olsl.library.utils.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.antis.olsl.activity.purchaseQuery
 * @ClassName: OrderGoodsDetailsActivity
 * @Description: 订单商品详情
 * @Author: 羊琪
 * @CreateDate: 2020/3/30 19:48
 * @UpdateDate: 2020/3/30 19:48
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class OrderGoodsDetailsActivity extends BaseActivity<ActivityOrderGoodsDetailsBinding> {

    private ArrayList<GoodsFiledInfo> filedInfos = new ArrayList<>();
    private DistributionInfoFiledListAdapter adapter;
    private boolean fromSalesroom = false;
    private String productId;
    private String purchaseNumber;

    @Override
    protected ActivityOrderGoodsDetailsBinding getViewBinding() {
        return ActivityOrderGoodsDetailsBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @Override
    protected void initViews() {
        viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new DistributionInfoFiledListAdapter(filedInfos);
        viewBinding.recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() throws IllegalAccessException {
        getDetails();
    }

    /**
     * 获取商品详情
     */
    private void getDetails() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("orderNumber", purchaseNumber);
        map.put("productId", productId);
        // okHttpClient.postJsonObjectParams(fromSalesroom ? UrlServerConnections.GET_GOODS_DETAILS_FOR_ORDER : UrlServerConnections.GET_GOODS_DETAILS_FOR_ORDER, map, GetOrderGoodsDetailsRes.class);
    }

    private void setData(GetOrderGoodsDetailsData detailsData) {
        if (detailsData == null) {
            return;
        }
        if (detailsData.getGoodsInfo() != null) {
            viewBinding.tvGoodsName.setText(detailsData.getGoodsInfo().getProductName());
            viewBinding.tvBarCode.setText(detailsData.getGoodsInfo().getBarCode());
            viewBinding.tvCommodityCode.setText(detailsData.getGoodsInfo().getProductCode());
            viewBinding.tvSpecificationOfGoods.setText(detailsData.getGoodsInfo().getSpecification());
        }

        if (detailsData.getOrderInfo() != null) {
            OrderInfo distributionSlipInfo = detailsData.getOrderInfo();
            filedInfos.add(new GoodsFiledInfo("订货日期", distributionSlipInfo.getCreateTime()));
            filedInfos.add(new GoodsFiledInfo("门店名称", distributionSlipInfo.getSalesroomName()));
            filedInfos.add(new GoodsFiledInfo("订货单号", purchaseNumber));
            filedInfos.add(new GoodsFiledInfo("批次号", distributionSlipInfo.getBatchNumber()));
            filedInfos.add(new GoodsFiledInfo("配送单号", distributionSlipInfo.getDistributionNumber()));
            filedInfos.add(new GoodsFiledInfo("出库单号", distributionSlipInfo.getEXWarehouseNumber()));
            filedInfos.add(new GoodsFiledInfo("入库单号", distributionSlipInfo.getInWarehouseNumber()));
            filedInfos.add(new GoodsFiledInfo("订货总数", StringUtils.getCommaFormat(new BigDecimal(distributionSlipInfo.getOrderNum()))));
            filedInfos.add(new GoodsFiledInfo("配送总数", StringUtils.getCommaFormat(new BigDecimal(distributionSlipInfo.getDistributionNum()))));
            filedInfos.add(new GoodsFiledInfo("到货总数", StringUtils.getCommaFormat(new BigDecimal(distributionSlipInfo.getReceiveNum()))));
        }
        adapter.setList(filedInfos);
    }

//    @Override
//    public void successResponse(BaseRes baseRes) {
//        if (baseRes instanceof GetOrderGoodsDetailsRes) {
//            GetOrderGoodsDetailsRes goodsDetailsRes = (GetOrderGoodsDetailsRes) baseRes;
//            setData(goodsDetailsRes.getContent());
//        }
//    }
}
